package com.dodoke.controller;

import java.util.Date;

import com.dodoke.common.constant.Constants;
import com.dodoke.domain.WxUser;
import com.dodoke.service.IWxUserService;
import com.dodoke.service.WxLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.dodoke.common.core.controller.BaseController;
import com.dodoke.common.core.domain.AjaxResult;

/**
 * 【微信用户模块】Controller
 *
 * @author dodoke
 * @date 2020-08-25
 */
@Api("微信用户管理")
@RestController
@RequestMapping("/wx_user")
public class WxUserController extends BaseController
{
    @Autowired
    private IWxUserService wxUserService;

    @Autowired
    private WxLoginService wxLoginService;

    /***
     * 登录
     * @return
     */
    @RequestMapping(value = "/wx_login",method = RequestMethod.POST)
    public AjaxResult wxLogin(WxUser wxUser) {
        AjaxResult ajax = AjaxResult.success();
        String token = wxLoginService.wxLogin(wxUser);
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }

    /***
     * 查询用户剩余的抽奖次数
     * @param openId 用户身份唯一标识
     * @return 抽奖次数
     */
    @ApiOperation("查询用户剩余的抽奖次数")
    @ApiImplicitParam(name = "openId",value = "用户身份唯一标识",dataType = "String",paramType = "path")
    @ApiResponse(code = 200,message = "请求成功")
    @RequestMapping("/selectUserOperCount/{openId}")
    public AjaxResult selectUserOperCount(@PathVariable String openId) {
        int count = wxUserService.selectUserOperCountByOpenId(openId);
        return AjaxResult.success(count);
    }

    @ApiOperation("更新用户剩余的抽奖次数")
    @ApiImplicitParam(name = "wxUser",value = "微信用户对应的实体类",dataType = "WxUser",paramType = "query")
    @RequestMapping("/updateUserOperCount")
    public AjaxResult updateUserOperCount(WxUser wxUser) {
        int i = wxUserService.updateWxUser(wxUser);
        return toAjax(i);
    }

}
